// pages/productDetail/productDetail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.id) {
      this.setData({
        anni_id: options.id
      })
    }
    allReqeust(this);
    getPhone(this);
    var that = this
    wx.getSystemInfo({//获取滑块的高宽
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight,
          imageUrl: app.globalData.imageUrl
        });
      }
    });
  },

  calling: function (e) {
    wx.makePhoneCall({
      phoneNumber: '' + e.target.id,
    })
  }
})

function getAnniDetail(that) {
  return new Promise((resovle, reject) => {
    wx.request({
      url: app.globalData.allUrl + "/goods/goodsinfo",
      data: {
        id: that.data.anni_id
      },
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
    //    console.log(res.data)
        if (res.data.data) {
          that.setData({
            anniDetail: res.data
          })
        }
        resovle(true);
      }, fail: function () {
        reject(false)
      }
    })
  })
}

async function allReqeust(that) {
  const _getAnniDetail = await getAnniDetail(that);
}

function getPhone(that) {
  wx.request({
    url: app.globalData.allUrl + "/user/get_phone",
    data: {
    },
    header: { 'content-type': "application/x-www-form-urlencoded" },
    method: 'POST',
    success: function (res) {
      that.setData({
        shopPhone: res.data[0].phone
      })
    }
  })
}